package com.example.controller;

import com.example.pojo.*;

import com.example.service.ClazzService;
import com.example.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClazzController 类的描述信息
 *
 * @author 12427
 * @since 2025/6/3 22:28
 */
@Slf4j
@RestController
@RequestMapping("/clazzs")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
    /**
     * 查询所有班级
     */
    @GetMapping("/list")
    public Result getAll() {
        List<Clazz> list = clazzService.getAll();
        log.info("查询所有");
        return Result.success(list);
    }
    /**
     *  查询所有班级  分页展示
     */
    @GetMapping
    public Result getList(ClazzQueryParam clazzQueryParam){
        log.info("分页查询{}",clazzQueryParam);
       PageResult<Clazz> pageResult = clazzService.page(clazzQueryParam);

        return Result.success(pageResult);
    }

    /**
     * 删除班级
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        clazzService.delete(id);
        return Result.success();
    }

    /**
     * 添加班级
     */
    @PostMapping
    public Result insetr(@RequestBody Clazz clazz) {
        clazzService.insert(clazz);
        return Result.success();
    }

    /**
     * 根据id查询
     */
    @GetMapping("/{id}")
    public Result  getById(@PathVariable("id") Integer id){
     Clazz clazz= clazzService.getById(id);
        return Result.success(clazz);
    }
    /**
     * 修改班级
     */
    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        log.info("修改用户");
        clazzService.update(clazz);
        return Result.success();
    }

}
